CXX = g++
CXXFLAGS = -Wall -Wextra -Werror -std=c++23 -O0 -g
LDFLAGS =
INCLUDES = -I./include
FLEX = flex
# 源文件定义
SRCS = $(wildcard src/*.cpp)
FLEX_SRCS = $(wildcard src/*.l)
FLEX_OBJS = $(patsubst src/%.l,src/flex/%.cpp,$(FLEX_SRCS))

SRCS += $(FLEX_OBJS)
OBJS = $(patsubst src/%.cpp,build/%.o,$(filter-out $(FLEX_OBJS),$(SRCS))) \
       $(patsubst src/flex/%.cpp,build/flex/%.o,$(FLEX_OBJS))

TARGET = minisql

#不删除临时文件...不然ide会报错缺少函数
.PRECIOUS: src/flex/%.cpp
# 创建目录
mkdir:
	mkdir -p build
	mkdir -p build/flex
	mkdir -p src/flex

build:mkdir $(OBJS)
	$(CXX) $(LDFLAGS) $(OBJS) -o $(TARGET)
src/flex:
	mkdir -p src/flex

# Flex 规则
src/flex/%.cpp: src/%.l | src/flex
	$(FLEX)  -o $@ $<

# 编译规则
build/%.o: src/%.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@

build/flex/%.o: src/flex/%.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@	

# 清理规则
clean:
	rm -r build src/flex $(TARGET)

# 默认目标
.PHONY: all
all: build $(TARGET)
